

using System;
using System.Collections.Generic;
using System.Text;
using DataAccessLayer;
using EntityLayer;
using DataLayer;
using System.Data;
using InfraStructureLayer;

namespace BusinessLayer
{
	public class busCategories:BusinessBase
	{
		public busCategories() : base()
		{
		}
		#region  Code Factory Generated Methods

		public DataTable SelectCategories()
		{
			try
			{
				datCategories insDatCategories = new datCategories();
				DbConnector insDbConnector = new DbConnector();
				return insDatCategories.SelectCategories(insDbConnector);
			}
			catch (SFException ex)
			{
				this.ErrorMessage = ex.Message;
			}
			return null;
		}
		public void SelectCategoriesByCategoryId(entCategories parEntCategories)
		{
			try
			{
				datCategories insDatCategories = new datCategories();
				DbConnector insDbConnector = new DbConnector();
				insDatCategories.SelectCategoriesByCategoryId(parEntCategories, insDbConnector);
			}
			catch (SFException ex)
			{
				this.ErrorMessage=ex.Message;
			}
		}
		
		#endregion
        public void DeleteCategoriesByCategoryId(entCategories parEntCategories)
        {
            DbConnector insDbConnector = new DbConnector();
            try
            {
                insDbConnector.BeginTransaction();

                datEntryCategories insDatEntryCategories = new datEntryCategories();
                entEntryCategories insEntEntryCategories = new entEntryCategories();
                insEntEntryCategories.CategoryId = parEntCategories.CategoryId;
                if (insDatEntryCategories.SelectEntryCategoriesByCategoryId(insEntEntryCategories, insDbConnector).Rows.Count > 0)
                {
                    throw new SFBusinessException(GetErrorMessageMultilanguageString(30, new object[] { }));
                }

                datCategoriesContents insDatCategoriesContents = new datCategoriesContents();
                entCategoriesContents insEntCategoriesContents = new entCategoriesContents();
                insEntCategoriesContents.CategoryId = parEntCategories.CategoryId;
                insDatCategoriesContents.DeleteCategoriesContentsByCategoryId(insEntCategoriesContents, insDbConnector);

                datCategories insDatCategories = new datCategories();
                insDatCategories.DeleteCategoriesByCategoryId(parEntCategories, insDbConnector);

                insDbConnector.CommitTransaction();
            }
            catch (SFException ex)
            {
                insDbConnector.RollbackTransaction();
                this.ErrorMessage = ex.Message;
            }
            catch (Exception ex)
            {
                insDbConnector.RollbackTransaction();
                throw new SFUnHandledException(ex);
            }
        }

        public void InsertCategories(entCategories parEntCategories)
        {
            DbConnector insDbConnector = new DbConnector();
            try
            {

                insDbConnector.BeginTransaction();
                datCategories insDatCategories = new datCategories();
                insDatCategories.InsertCategories(parEntCategories, insDbConnector);

                datCategoriesContents insDatCategoriesContents = new datCategoriesContents();
                foreach (entCategoriesContents insEntCategoriesContents in parEntCategories.CategoriesContentsInsert)
                {
                    insEntCategoriesContents.CategoryId = parEntCategories.CategoryId;
                    insDatCategoriesContents.InsertCategoriesContents(insEntCategoriesContents, insDbConnector);
                }
                foreach (entCategoriesContents insEntCategoriesContents in parEntCategories.CategoriesContentsUpdate)
                {
                    insEntCategoriesContents.CategoryId = parEntCategories.CategoryId;
                    insDatCategoriesContents.UpdateCategoriesContentsByCategoryContentId(insEntCategoriesContents, insDbConnector);
                }
                foreach (entCategoriesContents insEntCategoriesContents in parEntCategories.CategoriesContentsDelete)
                {
                    insDatCategoriesContents.DeleteCategoriesContentsByCategoryContentId(insEntCategoriesContents, insDbConnector);
                }
                insDbConnector.CommitTransaction();
            }
            catch (SFException ex)
            {
                insDbConnector.RollbackTransaction();
                this.ErrorMessage = ex.Message;
            }
            catch (Exception ex)
            {
                insDbConnector.RollbackTransaction();
                throw new SFUnHandledException(ex);
            }
        }
        public void UpdateCategoriesByCategoryId(entCategories parEntCategories)
        {
            DbConnector insDbConnector = new DbConnector();
            try
            {

                insDbConnector.BeginTransaction();
                datCategories insDatCategories = new datCategories();
                insDatCategories.UpdateCategoriesByCategoryId(parEntCategories, insDbConnector);

                datCategoriesContents insDatCategoriesContents = new datCategoriesContents();
                foreach (entCategoriesContents insEntCategoriesContents in parEntCategories.CategoriesContentsInsert)
                {
                    insEntCategoriesContents.CategoryId = parEntCategories.CategoryId;
                    insDatCategoriesContents.InsertCategoriesContents(insEntCategoriesContents, insDbConnector);
                }
                foreach (entCategoriesContents insEntCategoriesContents in parEntCategories.CategoriesContentsUpdate)
                {
                    insEntCategoriesContents.CategoryId = parEntCategories.CategoryId;
                    insDatCategoriesContents.UpdateCategoriesContentsByCategoryContentId(insEntCategoriesContents, insDbConnector);
                }
                foreach (entCategoriesContents insEntCategoriesContents in parEntCategories.CategoriesContentsDelete)
                {
                    insDatCategoriesContents.DeleteCategoriesContentsByCategoryContentId(insEntCategoriesContents, insDbConnector);
                }
                insDbConnector.CommitTransaction();
            }
            catch (SFException ex)
            {
                insDbConnector.RollbackTransaction();
                this.ErrorMessage = ex.Message;
            }
            catch (Exception ex)
            {
                insDbConnector.RollbackTransaction();
                throw new SFUnHandledException(ex);
            }
        }

        public DataTable SelectCategoriesByLanguageId()
        {
            try
            {
                DbConnector insDbConnector = new DbConnector();
                datCategories insDatCategories = new datCategories();
                return insDatCategories.SelectCategoriesByLanguageId(insDbConnector);
            }
            catch (SFException ex)
            {
                this.ErrorMessage = ex.Message;
            }
            return null;
        }
	}
}